package com.xxl.job.admin.condition;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.type.AnnotatedTypeMetadata;

/**
 * @author hujj
 * @version 1.0
 * @date 2021/6/2/002 14:20
 */
@Slf4j
public class DevApplicationCondition implements Condition {

    @Override
    public boolean matches(ConditionContext context,
                           AnnotatedTypeMetadata metadata) {
        if(context.getEnvironment()==null
                ||context.getEnvironment().getActiveProfiles()==null
                ||context.getEnvironment().getActiveProfiles().length<1) {
            return false;
        }
        String profile = context.getEnvironment().getActiveProfiles()[0];
        if("dev".equalsIgnoreCase(profile)) {
            return true;
        }
        return false;
    }
}
